/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mycompany.yourtrade.common;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.UUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.apache.commons.io.FileUtils;

import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.web.multipart.MultipartFile;

@Component
public class UpYunService {

    @Autowired
    private MessageChannel ftpChannel;

    public boolean Test(String filePath) {
        final File fileToSendA = new File(filePath);
        final Message<File> messageA = MessageBuilder.withPayload(fileToSendA).build();
        boolean result = ftpChannel.send(messageA);
        return result;
    }

    public String Test(MultipartFile file) throws IOException {
        String newName = "tianxia_".concat(UUID.randomUUID().toString());
        try {
            File convFile = new File(newName);
            file.transferTo(convFile);
            final Message<File> messageA = MessageBuilder.withPayload(convFile).build();
            if (ftpChannel.send(messageA)) {
                return newName;
            }

        } catch (Exception e) {

        }
        return null;
    }
}
